package gdconf

import (
	"server_cluster/common/logger"
)

// 抽卡概率配置表

type GachaProbConfig struct {
	Id            int32 `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 抽卡概率规则id
	ProbId        int32 `csv:"Poolgroup,omitempty"`                       // 概率规则组id
	FixGachaNum   int32 `csv:"Fixtime,omitempty"`                         // 固定抽数
	NormalPropId  int32 `csv:"Normal,omitempty"`                          // 普通抽概率库
	SpecialPropID int32 `csv:"Sepcial,omitempty"`                         // 保底抽概率库
}

func (c *GachaProbConfig) TableName() string {
	return "config_gacha_prob"
}

func (g *GameDataConfig) saveGachaProb() {
	saveTableToDb[GachaProbConfig](g.Db, readTable[GachaProbConfig](g.CsvPathPrefix+"CardDetail.csv"))
}
func (g *GameDataConfig) loadGachaProbConfig() {
	g.GameDataMaps.GachaProbMap = make(map[int32]*GachaProbConfig)
	for _, gachaProb := range loadTableFromDb[GachaProbConfig](g.Db) {
		g.GameDataMaps.GachaProbMap[gachaProb.ProbId*1000+gachaProb.FixGachaNum] = gachaProb
	}
	logger.Info("GachaProbConfig Count: %v", len(g.GameDataMaps.GachaProbMap))
}

func GetConfigGachaProbMap() map[int32]*GachaProbConfig { return CONF.GameDataMaps.GachaProbMap }

func GetConfigGachaProb(id, gachaNum int32) *GachaProbConfig {
	data, ok := CONF.GameDataMaps.GachaProbMap[id*1000+gachaNum]
	if !ok {
		return nil
	}
	return data
}
